﻿<%@ page language="java" 
    contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<%@ page import = "java.sql.*" %>
<html>
<head>
	<meta http-equiv="Content-Type" 
      content="text/html; charset=UTF-8">
	<title>所有用户信息</title>
</head>
<body>

<%!
      Connection conn = null;
      Statement stmt = null;
      ResultSet rs = null;
      
	  int id1 = 0;
      String name1 = "";
      String password1 = "";

%>
   <table align="center" width="450" border="1" height="240">
      <tr>
		<td align="center" colspan="3" 
			style="font-family:'黑体'; font-size:28px;" >
			所有用户信息
		</td>
      </tr>
      <tr align="center" style="color:white;background:red;">
		<td><b>用户名</b></td>
		<td><b>密  码</b></td>
        <td><b>操  作</b></td>
      </tr>

<%
try {
      // 加载数据库驱动，注册到驱动管理器
      Class.forName("com.mysql.jdbc.Driver");
      // 数据库连接字符串
      String url = "jdbc:mysql://localhost:3306/user2";
      // 数据库用户名
      String username = "root";
      // 数据库密码
      String password = "1234";
      // 创建Connection连接
      conn = DriverManager.getConnection(url,username,password);
      
	  // 获取Statement对象
      stmt = conn.createStatement();
      // 构造查询用户信息的SQL语句
      String sql = "select * from user_b";
      // 执行查询
      rs = stmt.executeQuery(sql);

      // 判断光标向后移动，并判断是否有效
      while(rs.next()){
         // 获取用户id
         id1 = rs.getInt("uid");
         // 获取用户名
         name1 = rs.getString("uname");
         // 获取密码
         password1 = rs.getString("upassword");

		 // 输出到页面
%>
         <tr align="center" style="color:red;backgound:white">
            <td><%=name1%></td>
            <td><%=password1%></td>
			<td><a href="DoDeleteUser.jsp?id1=<%=id1 %>">删除本条记录</a></td>            
         </tr>

<%
       }

       rs.close();		// 关闭ResultSet
       stmt.close();	// 关闭Statement
       conn.close();	// 关闭Connection

 } catch (ClassNotFoundException e) {
       e.printStackTrace();
 } catch (SQLException e) {
       e.printStackTrace();
 } 
%>
  </table>
  
  	<br>
	<a href="index.jsp"><font size="20">返回首页</font></a>
  
</body>
</html>